import datetime
import logging

from absl import app

from coin.exchange.okex.kr_rest.product import OkexProduct
import experimental.prophet as prophet


def model():
  ts = prophet.global_timestamp()
  timer_1s = prophet.timer('1s')

  product1 = OkexProduct.FromStr('BTC-USDT')
  product2 = OkexProduct.FromStr('ETH-USDT')
  feed1 = prophet.fastfeed_coin(product1, 'Spot.Okex.v3')
  feed2 = prophet.fastfeed_coin(product2, 'Spot.Okex.v3')

  proto1 = prophet.proto_from_fastfeed(feed1, ticksize=1, raw_ticksize=1).named_ref('proto1')
  proto2 = prophet.proto_from_fastfeed(feed2, ticksize=1, raw_ticksize=1).named_ref('proto2')

  aggregator = prophet.scalar_value_aggregator([ts])
  # aggregator = prophet.scalar_value_aggregator([ts, proto1, proto2])

  return aggregator


def main(argv):
  df = prophet.run_from_fastfeed_multiprocess(model,
                                              datetime.date(2019, 7, 1),
                                              datetime.datetime(2019, 7, 1, 0, 1),
                                              machine='feed-01.ap-northeast-1.aws',
                                              use_run_cache=False,
                                              eval_updated_only=False)

  # assert (df.proto1 == df.proto2).all()


if __name__ == '__main__':
  logging.basicConfig(level='DEBUG')
  app.run(main)
